<#include "/layout/layout.ftl">
<#import "/layout/macro.ftl" as macro>
<#import "/layout/select.ftl" as my/>
<#assign css>
<#--此ftl中用到的css-->
<link rel="stylesheet" href="/assets/vendor/bootstrap-datetimepicker/css/bootstrap-datetimepicker.min.css">

</#assign>
<#assign js>
<#--此ftl中用到的js-->
<script src="/assets/vendor/bootstrap-datetimepicker/js/bootstrap-datetimepicker.min.js"></script>
<script src="/assets/vendor/bootstrap-datetimepicker/js/locales/bootstrap-datetimepicker.zh-CN.js"></script>
<script>
	$(".btn-submit").click(function () {
	    debugger;
		// 校验表单合法
		var bootstrapValidator = $(".form-edit").data('bootstrapValidator');
		bootstrapValidator.validate();
		if(bootstrapValidator.isValid()){
			$.ajax({
				type: "POST",
				url: "/weather/edit",
				data: $(".form-edit").serialize(),
				dataType: "JSON",
				success: function(res){
					layer.msg(res.message, {time: 2000
					}, function(){
						location.href="/weather/index";
					});
				}
			});
		}else{
			return false;
		}
	});


    $("#weatherId").change(function (e) {
        var weatherId = e.currentTarget.value;

        <#list weatherList as wea>
			if('${wea.weatherId}'==weatherId){
                $("#weatherDesc").val('${wea.weatherName}');
                $("#reward").val('${wea.amt}');
			}

        </#list>

    });

    $('#startTime,#endTime').datetimepicker({
        autoclose: true,
        format:"yyyy-mm-dd hh:ii:00",
        todayHighlight:true,
        language:"zh-CN",
		startDate:new Date()
    });


    $('#startTime').unbind("change");
    $('#startTime').change(function(){
        $('#endTime').datetimepicker('setStartDate', $("#startTime").val());
    });
    $('#endTime').unbind("change");
    $('#endTime').change(function(){
        $('#startTime').datetimepicker('setEndDate', $("#endTime").val());
    });



	$('.form-edit').bootstrapValidator({
		message: '请输入有效值',
		feedbackIcons: {
			valid: 'glyphicon glyphicon-ok',
			invalid: 'glyphicon glyphicon-remove',
			validating: 'glyphicon glyphicon-refresh'
		}
	});

</script>
</#assign>
<@layout title="编辑" active="weather">
<!-- Content Header (Page header) -->
<section class="content-header">
	<h1>
		<#if isAdd>
            新增
        <#else>
            编辑
        </#if>
		<small>特殊天气设置详细信息</small>
	</h1>
	<ol class="breadcrumb">
		<li><a href="/"><i class="fa fa-home"></i> 管理后台</a></li>
		<li><a href="#"><i class="fa fa-list-ul"></i> 特殊天气设置管理</a></li>
		<li class="active"><i class="fa fa-edit"></i>
		    <#if isAdd>
                新增
            <#else>
                编辑
            </#if>
		</li>
	</ol>
</section>
<!-- Main content -->
<section class="content">
	<div class="row">
		<div class="col-md-12">
			<!-- Default box -->
			<div class="box  box-primary">
				<form class="form-horizontal form-edit" method="post" action="weather/edit">
					<div class="box-body">
						<input type="hidden" id="id" name="id" value="${weather.id!}">
						<input type="hidden" id="weatherDesc" name="weatherDesc" value="${weather.weatherName!}">
						<input type="hidden" id="isAdd" name="isAdd" value="${isAdd?string('true','false')}">

						<div class="form-group">
							<label class="col-sm-2 control-label">特殊天气：</label>
							<div class="col-sm-10">
								<select id="weatherId" name="weatherId" required class="form-control">
									<option value="" >请选择</option>
									<#list weatherList as w>
										<option value="${w.weatherId}">${w.weatherName}</option>
									</#list>
								</select>

							</div>
						</div>
                        <div class="form-group">
                            <label class="col-sm-2 control-label">特殊天气奖励金额：</label>
                            <div class="col-sm-10">
                                <input required placeholder="请输入特殊天气奖励金额" id="reward" name="reward" class="form-control" type="text" value="${weather.reward!}" >
                            </div>
                        </div>

						<div class="form-group">
							<label class="col-sm-2 control-label">开始时间：</label>
							<div class="col-sm-10">
								<input placeholder="请输入开始时间" required id="startTime" name="startTime" class="form-control" type="text" value="${weather.startTime!}" >
							</div>
						</div>
						<div class="form-group">
							<label class="col-sm-2 control-label">结束时间：</label>
							<div class="col-sm-10">
								<input placeholder="请输入结束时间" required id="endTime" name="endTime" class="form-control" type="text" value="${weather.endTime!}" >
							</div>
						</div>



					<div class="box-footer">
						<button type="button" class="btn btn-default btn-back">返回</button>
						<button type="button" class="btn btn-info pull-right btn-submit">提交</button>
					</div>

				</form>
			</div>
			<!-- /.box -->
		</div>
	</div>
</section>
<!-- /.content -->
</@layout>
